/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package data;

import entities.ArtPhoto;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;

/**
 *
 * @author bertram
 */
public class PhotoCache {

    private static HashMap<String, ArrayList<ArtPhoto>> photoMap = new HashMap<String, ArrayList<ArtPhoto>>();
    private static LinkedList<String> keys = new LinkedList<String>();

    public static ArrayList<ArtPhoto> getPhotos(String ID)
    {
        return photoMap.get(ID);
    }

    public static synchronized String addPhotos(ArrayList<ArtPhoto> photos)
    {
        String token = TokenCache.generateToken();
        photoMap.put(token, photos);
        keys.addLast(token);
        if(keys.size() > 100) photoMap.remove(keys.removeFirst());
        return token;
    }
    public static synchronized void clearCache()//maintanance method for clearing this cache.
    {
        photoMap = new HashMap<String, ArrayList<ArtPhoto>>();
        keys = new LinkedList<String>();
    }

}
